package com.zlx.mall.basic.util;

import java.util.concurrent.ThreadLocalRandom;

/**
 * @Author xiatian
 * @Date 2024/6/13 星期四 14:57
 * @注释
 */
public class DataNoGenerator {
    /**
     * 去除字母 I 和 O，因为这两个字母 和 数字 1，0 相似
     */
    private static final String[] STR = new String[]{"F", "N", "A", "5", "E", "7", "V", "4", "D", "C", "1", "3", "X", "G", "T", "9", "Z", "6", "M", "Q", "S", "H", "B", "8", "L", "W", "U", "K", "0", "R", "2", "Y", "J"};
    //前缀必须非 str 串类的数字  因为字母O  和0 形似，所以取O作为前缀
    private static final String PREFIX = "P";

    /**
     * 用户邀请码 生成器
     * 原理： 将id 转化成 33进制 进制位的符号 根据str 的下标字符表示
     * 多余的字符串向后追加，id转化的字符 用非进制字符串数据内的字母进行分割，即可保证唯一，并且能使得出现的字母随机
     *
     * @param value 用户id
     * @return String 邀请码
     */
    public static String generateInvite(long value) {
        long mod = 0;
        StringBuilder sb = new StringBuilder();
        while (value != 0) {
            mod = value % STR.length;
            value = value / STR.length;
            sb.append(STR[(int) mod]);
        }
        if (sb.length() < 6) {
            sb.append(PREFIX);
        }
        while (sb.length() < 6) {
            sb.append(STR[ThreadLocalRandom.current().nextInt(STR.length - 1)]);
        }
        return sb.toString();
    }

    /**
     * 优惠券商品订单号前缀
     */
    public static final String SHOP_MALL_COUPON_ORDER = "SPC";

    /**
     * 商品订单号前缀
     */
    public static final String SHOP_MALL_ORDER = "XSYX";
    /**
     * 商品订单号前缀
     */
    public static final String DATA_PLATFORM_ORDER = "DPO";
    /**
     * 商品订单 （包括普通商品和优惠券商品）自增key
     */
    public static final String SMO_INCR_KEY = "guid:incr:sp_incr_key";
    /**
     * 商品订单 （包括普通商品和优惠券商品）自增key
     */
    public static final String DATA_PLATFORM_INCR_KEY = "guid:incr:pf_incr_key";

    /**
     * 支付订单号
     */
    public static final String ORDER_ZFB_PAY_ORDER = "ZF";
    /**
     * 支付订单自增key
     */
    public static final String POD_ZFB_INCR_KEY = "guid:incr:pay:zf:key";
    /**
     * 银行卡支付订单号
     */
    public static final String ORDER_BANK_PAY_ORDER = "BK";
    /**
     * 银行卡支付自增key
     */
    public static final String POD_BANK_INCR_KEY = "guid:incr:pay:bk:key";
    /**
     * 微信支付订单号
     */
    public static final String ORDER_WX_PAY_ORDER = "WX";
    /**
     * 银行卡支付自增key
     */
    public static final String POD_WX_INCR_KEY = "guid:incr:pay:wx:key";
    /**
     * 银联快捷支付订单号
     */
    public static final String ORDER_FAST_PAY_ORDER = "FAST";
    /**
     * 银联支付支付自增key
     */
    public static final String POD_FAST_INCR_KEY = "guid:incr:pay:fast:key";
    /**
     * 提现流水号
     */
    public static final String USER_WITHDRAW_ORDER = "WD";
    /**
     * 银行卡支付自增key
     */
    public static final String USER_WITHDRAW_INCR_KEY = "guid:incr:withdraw:key";

    /**
     * 用户分享电话卡
     */
    public static final String SHARE = "SH";
    /**
     * 用户分享电话卡自增key
     */
    public static final String SHARE_KEY = "guid:incr:share:key";

    /**
     * 用户银行账户签约订单
     */
    public static final String USER_BANK_ACCOUNT_SIGNING_ORDER = "SO";
    /**
     * 用户银行账户签约订单自增key
     */
    public static final String USER_BANK_ACCOUNT_SIGNING_ORDER_INCR_KEY = "guid:incr:user:bank_account:key";


    /**
     * 平台信息
     */
    public static final String PLATFORM = "";

    /**
     * 比拼活动订单号
     */
    public static final String ACTIVITY_COMPETITION_ORDER="BP";

    /**
     * 商品订单 （包括普通商品和优惠券商品）自增key
     */
    public static final String BP_INCR_KEY = "guid:incr:bp_incr_key";
}

